<?php
require '../../../zb_system/function/c_system_base.php';
require '../../../zb_system/function/c_system_admin.php';
$zbp->Load();
$action='root';
if (!$zbp->CheckRights($action)) {$zbp->ShowError(6);die();}
if (!$zbp->CheckPlugin('sf_cache')) {$zbp->ShowError(48);die();}

$blogtitle = $zbp->LoadApp('plugin', 'sf_cache')->name.' Ver '.$zbp->LoadApp('plugin', 'sf_cache')->version.' @ '.$zbp->LoadApp('plugin', 'sf_cache')->modified.'<small style="float:right;"><a style="cursor: pointer;" class="up_button">[更新检测]</a></small>';
require $blogpath . 'zb_system/admin/admin_header.php';
require $blogpath . 'zb_system/admin/admin_top.php';
?>

<?php
$actiontype=GetVars('actiontype', 'POST');
if($actiontype == "set"){
	$zbp->Config('sf_cache')->diskenable=GetVars('diskenable','POST');
	$zbp->Config('sf_cache')->disktime=GetVars('disktime','POST');
	$zbp->Config('sf_cache')->clearCacheAfterPostArticle=GetVars('clearCacheAfterPostArticle','POST');
	$zbp->SaveConfig('sf_cache');
	$zbp->SetHint('good');
	Redirect('main.php');
}else if($actiontype == "clear"){
	sf_cache_deleteDir($blogpath .'/zb_users/plugin/sf_cache/cache');
	$zbp->SetHint('good');
	Redirect('main.php');
}

?>

<div id="divMain">
  <div class="divHeader"><?php echo $blogtitle;?></div>
  <div class="SubMenu">
  </div>
  <div id="divMain2">
<!--代码-->
	<div class="content-box">
		<!-- Start Content Box -->
		<div class="content-box-header">
			<ul class="content-box-tabs">
				<li><a href="#tab1" class="default-tab"><span>基础设置</span></a></li>
			</ul>
		</div>
		<!-- End .content-box-header -->
		<div class="content-box-content">
			<div class="tab-content default-tab" style="border:none;padding:0px;margin:0;" id="tab1">
			<form id="cacheform" name="cacheform" method="post" action="main.php">
			<input type='hidden' name="actiontype" value="set">
			<table name='base' style="padding:0px;margin:0px;width:100%;">
				<tr>
					<td class='td25'>
						<p><b>启用磁盘缓存</b></p>
					</td>
					<td>
						<p><input type="text" name="diskenable"  class="checkbox" value="<?php echo $zbp->Config('sf_cache')->diskenable;?>" style="display:none;"></p>
					</td>
				</tr>
				<tr>
					<td class='td25'>
						<p><b>自动清空缓存</b></p>
						<span class="note">&nbsp;编辑文章成功后自动清空缓存</span>
					</td>
					<td>
						<p><input type="text" name="clearCacheAfterPostArticle"  class="checkbox" value="<?php echo $zbp->Config('sf_cache')->clearCacheAfterPostArticle;?>" style="display:none;"></p>
					</td>
				</tr>
				<tr>
					<td class='td25'>
						<p><b>缓存时间设置 (分钟)</b></p>
						<span class="note">&nbsp;默认10分钟，可根据访问量设置。</span>
					</td>
					<td>
						<p><input type="number" name="disktime" style="width:400px;" value="<?php echo $zbp->Config('sf_cache')->disktime;?>" ></p>
					</td>
				</tr>
			</table>
			<input name="set" type="button" class="button" value="提交"/>&nbsp;&nbsp;
			<input name="clear" type="button" class="button" value="清空缓存"/>
			</form>
		</div>
	</div>
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){ 
	$('.up_button').click(function() {
		if (!$( '#dialog_ver' ).length){
			$('.up_button').html("Waiting...");
			$.ajax({
				type:'post',url: "<?php echo base64_decode('aHR0cHM6Ly93d3cuaW1sZ20uY29tL3piX3VzZXJzL3BsdWdpbi9DaGVja0FwcC92ZXIucGhw');?>",
				async:true,timeout:30000,
				data:{
					guest_apptype:'<?php $app = $zbp->LoadApp('plugin', 'sf_cache');echo $app->type;?>', 
					guest_appid:'<?php echo $app->id;?>', 
					guest_appmodified:'<?php echo $app->modified;?>', 
					guest_host:'<?php echo $zbp->host;?>',
					guest_ip:'<?php echo GetGuestIP();?>',
					guest_name:'<?php echo $zbp->Config('AppCentre')->username;?>'
				},
				dataType:'json',complete:function(){},
				success:function(data){
						$('body').append(data);
						$( '#dialog_ver' ).dialog();
						$('.up_button').html("[更新检测]");
				},
				error:function(){
					var errtxt = "<div id='dialog_ver' title='版本更新提示'><p>参数提交错误</p></div>";
						$('body').append(errtxt);
						$( '#dialog_ver' ).dialog();
				}
			});
		}else{
			$( '#dialog_ver' ).dialog();	
		}
	});
})
</script>
<script type="text/javascript">
$(document).ready(function(){
	$("table[name='base'] tr:even").addClass("color2");
	$("table[name='base'] tr:odd").addClass("color3");
	$("input[name='clear']").click(function(){
		$("input[name='actiontype']").val("clear");
		$("#cacheform").submit();
	});
	$("input[name='set']").click(function(){
		$("input[name='actiontype']").val("set");
		var time=$("input[name='disktime']").val();
		var re = /^\d+$/;
		var flag=re.test(time);
		if(flag!=true){
			alert("请填入正整数");
			return;
		}
		$("#cacheform").submit();
	});
});
</script>

<?php
require $blogpath . 'zb_system/admin/admin_footer.php';
RunTime();
?>